<template>
    <div class="photoInfo-container">
        <h3 class="photoInfo-title">{{photoInfo.title}}</h3>
        <p class="subtitle">
            <span>发表时间：{{photoInfo.add_time | dateFormat}}</span>
            <span>点击：{{photoInfo.click}}次</span>
        </p>
        <hr>
        <vue-preview class="img" :slides="list" @close="handleClose"></vue-preview>
        <div class="content" v-html="photoInfo.content"></div>
        <cmt-box :id="id"></cmt-box>
    </div>
</template>

<script>
    import comment from '../subcomponents/comment.vue'
    export default {
        data() {
            return {
                id: this.$route.params.id,//从路由中获取到的图片ID
                photoInfo: {},
                list: []
            }
        },
        created() {
            this.getPhotoInfo();
            this.getThumbs();
            this.handleClose();
        },
        methods: {
            getPhotoInfo() {
                this.$http.get('http://www.liulongbin.top:3005/api/getimageInfo/' + this.id).then(result => {
                    var result = result.body;
                    if (result) {
                        this.photoInfo = result.message[0];
                    }
                })
            },
            getThumbs() {
                this.$http.get('http://www.liulongbin.top:3005/api/getthumimages/' + this.id).then(result => {
                    var result = result.body;
                    if (result) {
                        result.message.forEach(item => {
                            item.w = 600;
                            item.h = 400;
                            item.msrc = item.src;
                        });

                        this.list = result.message;
                    }
                })
            },
            handleClose(){

            }
        },
        components: {
            'cmt-box': comment
        }

    }
</script>

<style >
    .photoInfo-container {
        padding: 3px;

    }

    .photoInfo-container .photoInfo-title {
        color: #26a2ff;
        font-size: 15px;
        text-align: center;
        margin: 15px 0;
    }

    .photoInfo-container .subtitle {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
    }

    .photoInfo-container .content {
        font-size: 13px;
        line-height: 30px;
    }
    .img{
        padding: 10px;
    }
    .img figure{
        display: inline;
        margin: 0;
    }
    .img img{
        width: 100px;
        height: 100px;
        margin-top:10px;
        margin-right: 8px;
        box-shadow: 0 0 8px #999;
    }
</style>